package org.xyl.router;

import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 工具路由层 - 负责将请求路由到对应的工具实现
 */
@Component
public class ToolRouter {
    
    private final Map<String, ToolHandler> toolHandlers = new ConcurrentHashMap<>();
    
    /**
     * 注册工具处理器
     */
    public void registerTool(String toolName, ToolHandler handler) {
        toolHandlers.put(toolName, handler);
    }
    
    /**
     * 执行工具调用
     */
    public Object executeTool(String toolName, Map<String, Object> params) {
        ToolHandler handler = toolHandlers.get(toolName);
        if (handler == null) {
            throw new IllegalArgumentException("Unknown tool: " + toolName);
        }
        return handler.execute(params);
    }
    
    /**
     * 工具处理器接口
     */
    public interface ToolHandler {
        Object execute(Map<String, Object> params);
    }
}
